#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "QtGlobal"
#include <QMainWindow>
#include <QListView>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QModelIndex>
//#include <QtSerialPort/QSerialPort>

#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkAccessManager>
#include <QVector>
#include <serialportthread.h>
#include <scannerthread.h>
#include <beepthread.h>
#include <qmap.h>
#include <uguithread.h>
#include <qtimer.h>
#include <QUdpSocket>

namespace Ui {
class MainWindow;
}

class LoginDialog;
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void keyReleaseEvent(QKeyEvent *event);
    void keyPressEvent(QKeyEvent *event);
    void generateQRCode(char* code);
    QString quint8ToHexString(quint8* data, int len);
    void initialTable();
    void addPayline(QString str);
    void addTableline(QString name, QString price);
    void getTableline(QString code);
    void getTotal();
    void initial();
    virtual void timerEvent(QTimerEvent *event);
    void timerStart();
    void timerStop();
    void initialConfig();
    void writeDatagram(QByteArray data);
private:
    Ui::MainWindow *ui;
    QStandardItemModel *standardItemModel;
    //SettingsDialog *settings;
    //LoginDialog *loginDialog;
    //QSerialPort *serial;
    QStringList strList;

    QNetworkRequest httpRequest;
    QNetworkAccessManager networkAccessManager;
    QNetworkReply *reply;
    QString basicUrl;
     QString hostAddress="127.0.0.1";
     uint hostPort=6677;
    QHostAddress qHostAddress;
    SerialPortThread *portThread;
    ScannerThread *scannerThread;
    BeepThread *beepThread;
    UguiThread *uguiThread;
    QMap<QString, QString> PayList;
    QMap<QString, QString> tabList;
    bool isPaying;
    QString shopId;
    QString macId;
    QString tempStr;
    int timerID;
    QUdpSocket udpSocket;
    DebugLog *msgLog;
public slots:

    void sendDatagram(QString sendText);
    void processPendingDatagrams();
    QString makeReport(QString originalMsg);
    QString reConvert2Rport(QString back_report);
    void ProcessServerReport(QString serverMsg);
    //Button
    void ClickAppButton();
    void ClickWeButton();
    void ClickSeriSetButton();
    //Mesg
    void OutSerialMesg(quint8 cmd, quint8* data, int len);
    void OutScannerMesg(const QByteArray &data);
    void serviceRequestFinished(QNetworkReply *reply);
};

#endif // MAINWINDOW_H
